<?php $db = new Mypdo(); ?><?php

if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){

if(!empty($_GET['supprid'])&&!empty($_GET['id'])){


    if($_GET['supprid'] == $_GET['id']){
        $persManager = new PersonneManager($db);
        $partManager = new PartageManager($db);

        $partManager->delPartByIdPers($_GET['supprid']);
        $persManager->delPers($_GET['supprid']);

        header('Location: index.php?page=109');
    }
}else{
    if(empty($_POST)&&!empty($_GET['id'])){
        $persManager = new PersonneManager($db);
        $pers = $persManager->getPers($_GET['id']);
        ?>

        <h1>Détail personne</h1>

        <form method="post" action="#">

            <p>
            <h3>Identité</h3>
            <label for="genre_pers">Genre :</label><select name="genre_pers" id="genre_pers"  required="required">
                <option></option>
                <option value="M" <?php echo $pers->getGenrePers() == 'M'?'selected':''; ?>>M.</option>
                <option value="Mme" <?php echo $pers->getGenrePers() == 'Mme'?'selected':''; ?>>Mme.</option>
                <option value="Mlle" <?php echo $pers->getGenrePers() == 'Mlle'?'selected':''; ?>>Mlle.</option>
            </select>
            <label for="nom_pers">Nom:</label><input name="nom_pers" type="text" id="nom_pers" required="required" value="<?php echo $pers->getNomPers(); ?>" />
            <label for="prenom_pers">Prenom :</label><input type="text" name="prenom_pers" id="prenom_pers" required="required" value="<?php echo $pers->getPrenomPers(); ?>" /><br />

            </p>
            <p>
            <h3>Adresse</h3>

            <?php  $adresse = $pers->getAdressePers();  ?>

            <p>
                <label for="num_adresse">N°:</label><input name="num_adresse" type="text" id="num_adresse" min="0" value="<?php echo $adresse->getNumAdresse(); ?>" />
                <label for="voie_adresse">Voie :</label><input type="text" name="voie_adresse" id="voie_adresse" value="<?php echo $adresse->getVoieAdresse(); ?>" /><br />
                <label for="cp_adresse">Code Postal :</label><input type="text" name="cp_adresse" id="cp_adresse" value="<?php echo $adresse->getCpAdresse(); ?>" />
                <label for="ville_adresse">Ville :</label><input type="text" name="ville_adresse" id="ville_adresse" value="<?php echo $adresse->getVilleAdresse(); ?>"/><br />
            </p>


            </p>
            <p>
            <h3>Contact</h3>
            <label for="num_fix_pers">Numero fix</label><input name="num_fix_pers" type="text" id="num_fix_pers" required="required" value="<?php echo $pers->getNumFixPers(); ?>" />
            <label for="num_port_pers">Numero portable :</label><input type="text" name="num_port_pers" id="num_port_pers" value="<?php echo $pers->getNumPortPers(); ?>" /><br />
            <label for="email_pers">Email :</label><input type="text" name="email_pers" id="email_pers" value="<?php echo $pers->getEmailPers(); ?>" />
            </p>

            <p><input type="reset" value="Annuler" /><input type="submit" value="Modifier" />
                <input id="suppr" name="suppr" type="button" onclick="document.location.href='index.php?page=117&id=<?php echo $_GET['id']; ?>&supprid=<?php echo $pers->getIdPers(); ?>'" value="Supprimer" />
            </p>
        </form>

    <?php }else{
        $persManager = new PersonneManager($db);
        $persN = new Personne($_POST);
        $persN->setIdPers($_GET['id']);
        $persN->setAdressePers(new Adresse($_POST));
        $pers = $persManager->getPers($_GET['id']);



        $persManager->update($persN);
        header('Location: #');
    }
}
}else{
    header('Location: index.php');
}